package com.design.singleton;

import com.java.base.unsafe.UnsafeBean;
import sun.misc.Unsafe;

public class LazySingleton {

    private static volatile Singleton singleton;
    private static Singleton singletonU;

    public static Singleton get() {
        if (singleton == null) {
            synchronized (Singleton.class) {
                if (singleton == null) {
                    singleton = new Singleton();
                }
            }
        }
        return singleton;
    }

    public static Singleton getU() {
        if (singletonU == null) {
            synchronized (Singleton.class) {
                if (singletonU == null) {
                    Unsafe unsafe = UnsafeBean.get();
                    singletonU = new Singleton();
                    unsafe.loadFence();
                }
            }
        }
        return singletonU;
    }

}
